package com.cn.zpark.utils;

import java.io.Serializable;
import java.util.List;

/**
 * @PackageName: com.cn.zpark.utils
 * @ClassName: PageInfo
 * @Description:
 * @author: RZS
 * @date: 2022/4/22  20:04
 */
public class PageInfo<T> implements Serializable {
    // 总数量
    private Integer sumNumber;
    // 总页数
    private Integer pageNumber;
    // 当前页码
    private Integer currentPage;
    // 上一页
    private Integer upPage;
    // 下一页
    private Integer nextPage;
    // 每页显示数量
    private Integer number = 10;
    // 数据信息
    private List<T> info;

    public Integer getSumNumber() {
        return sumNumber;
    }

    public void setSumNumber(Integer sumNumber) {
        this.sumNumber = sumNumber;
    }

    public Integer getPageNumber() {
        // 计算总页数
        if(sumNumber % number == 0){
            pageNumber = sumNumber / number;
        }else{
            pageNumber = (sumNumber / number) + 1;
        }

        return pageNumber;
    }

    public void setPageNumber(Integer pageNumber) {
        this.pageNumber = pageNumber;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        // 设置上一页
        if(currentPage == 0){
            this.upPage = currentPage;
        }else{
            this.upPage = currentPage - 1;
        }
        // 设置下一页
        if(currentPage == pageNumber){
            this.nextPage = currentPage;
        }else{
            this.nextPage = currentPage + 1;
        }
        this.currentPage = currentPage;
    }

    public Integer getUpPage() {
        return upPage;
    }

    public void setUpPage(Integer upPage) {
        this.upPage = upPage;
    }

    public Integer getNextPage() {
        return nextPage;
    }

    public void setNextPage(Integer nextPage) {
        this.nextPage = nextPage;
    }

    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }

    public List<T> getInfo() {
        return info;
    }

    public void setInfo(List<T> info) {
        this.info = info;
    }

    @Override
    public String toString() {
        return "PageInfo{" +
                "sumNumber=" + sumNumber +
                ", pageNumber=" + pageNumber +
                ", currentPage=" + currentPage +
                ", upPage=" + upPage +
                ", nextPage=" + nextPage +
                ", number=" + number +
                ", info=" + info +
                '}';
    }
}
